/*------------------------------------------------------
                bsp层的板载led驱动函数
@brief functions:
.
.
.
.
@attention:

@auther:Cherno
--------------------------------------------------------*/
#include <main.h>
#include "bsp_led.h"

//=====================================================================================================

/*-----------------base communication functions
--------------------------------------------------------
@brief:
*/
//

/*----------------- base functions
--------------------------------------------------------
@brief:
*/
//

//=====================================================================================================

/*----------------- app functions
--------------------------------------------------------
@brief:
*/
//
void led_init(void)
{
    HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2);
    HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_3);
}

//
void aRGB_led_show(uint32_t aRGB)
{
    static uint8_t alpha;
    static uint16_t red, green, blue;

    alpha = (aRGB & 0xFF000000) >> 24;
    red = ((aRGB & 0x00FF0000) >> 16) * alpha;
    green = ((aRGB & 0x0000FF00) >> 8) * alpha;
    blue = ((aRGB & 0x000000FF) >> 0) * alpha;

    __HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_1, blue);
    __HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_2, green);
    __HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_3, red);
}

/*----------------- API_c
--------------------------------------------------------
@brief:
*/
//

/*------------------------end-------------------------*/